package com.itheim.controller;

import com.itheim.anno.Log;
import com.itheim.pojo.Dept;
import com.itheim.pojo.Result;
import com.itheim.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("/depts")
    public Result list(){
        List<Dept> deptList = deptService.findall();
        return Result.success(deptList);
    }

    @Log
    @DeleteMapping("/depts")
     public Result delete(Integer id) {
         deptService.deletebyId(id);
         return Result.success();
     }


    @Log
    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept) {

        deptService.add(dept);
        return Result.success();
    }
    @GetMapping("/depts/{id}")
    public Result getInfo(@PathVariable Integer id){
        Dept dept = deptService.getInfo(id);
        return Result.success(dept);
    }
    @Log
    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }
}
